package com.yh.csx.crm.core.enums;

import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ArchiveCategoryEnum class
 * 档案分类：01法人，02政府/事业单位，03军队，04其他非法人，05一次性客户
 * @author huyalin
 * @date 2019/2/21
 */
public enum ArchiveCategoryEnum {
    LEGAL_PERSON("01", "法人"),
    GOVERNMENT("02", "政府/事业单位"),
    TROOP("03", "军队"),
    OTHER("04", "其他非法人"),
    TEMP("05", "一次性客户");

    private String code;
    private String name;

    ArchiveCategoryEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    private static final Map<String, ArchiveCategoryEnum> valueLookup = new ConcurrentHashMap<>(values().length);
    static {
        for (ArchiveCategoryEnum type : EnumSet.allOf(ArchiveCategoryEnum.class)) {
            valueLookup.put(type.code, type);
        }
    }

    public static ArchiveCategoryEnum resolve(String code) {
        return (code != null ? valueLookup.get(code) : null);
    }

    public static String resolveName(String code) {
        ArchiveCategoryEnum category = resolve(code);
        return category == null ? "" : category.getName();
    }
}
